package com.jk.rabbitMQ;

import com.jk.dto.TemUser;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;


import java.io.IOException;
import java.util.Map;

/**
 * @author yzf
 * @version 1.0
 * @ClassName HelloReceiver
 * @program: yzf-test
 * @description: TODO
 * @date 2025/2/27 15:34
 */
@Component
public class HelloReceiver {
    // yzf TODO 2025/3/10 rabbitMQ 消费者:

    @RabbitListener(queues = "hello")
    public void process(String contrext) {
        System.out.println("接收的消息  : " + contrext);
    }
    @RabbitListener(queues = "object")
    public void processOjb(TemUser temUser){
        System.out.println("接收的消息: " + temUser.toString());

    }
    @RabbitListener(queues = "topic.message")
    public void processExchange(TemUser temUser){
        System.out.println("接收的消息exchange topic.message : " + temUser);
    }
    @RabbitListener(queues = "topic.messages")
    public void processExchanges (TemUser temUser, @Headers Map<String,Object> header, Channel channel) throws IOException {
        System.out.println("接收的消息exchange topic.messages : " + temUser);
        //设置手动应答
        Long deliveryTag = (Long) header.get(AmqpHeaders.DELIVERY_TAG);
        //手动签收
        channel.basicAck(deliveryTag,false);
    }

    @RabbitListener(queues = "fanout.A")
    public void processA(TemUser temUser){
        System.out.println("接收的消息fanout.A : " + temUser);

    }
    @RabbitListener(queues = "fanout.B")
    public void processB(TemUser temUser){
        System.out.println("接收的消息fanout.B : " + temUser);
    }
    @RabbitListener(queues = "fanout.C")
    public void processC(TemUser temUser){
        System.out.println("接收的消息fanout.C : " + temUser);
    }
}
